﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MOMKeLABS.Controls.Popup
{
    public partial class ContextPopupContainer : UserControl
    {
        public ContextPopupContainer()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Show this popup at the given top and left coords
        /// </summary>
        /// <param name="top"></param>
        /// <param name="left"></param>
        public void Show(double top, double left)
        {

            if((App.Current as App).VisualRoot.GetType() != typeof(MainPage))
                return;

            if (top < 0)
                top = 0;

            this.SetValue(Canvas.TopProperty, top);
            this.SetValue(Canvas.LeftProperty, left);
            this.SetValue(Canvas.ZIndexProperty, ((App.Current as App).VisualRoot as MainPage).Desktop.Children.Count + 1);
            ((App.Current as App).VisualRoot as MainPage).Desktop.Children.Add(this);

        }

        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if ((App.Current as App).VisualRoot.GetType() != typeof(MainPage))
                return;

            if (((App.Current as App).VisualRoot as MainPage).Desktop.ActualHeight < ((double)this.GetValue(Canvas.TopProperty) + this.ActualHeight))
            {
                this.SetValue(Canvas.TopProperty, ((App.Current as App).VisualRoot as MainPage).Desktop.ActualHeight - this.ActualHeight);
            }
        }

    }
}
